﻿using _11._21._2014_AngularWebAPI.adapters;
using _11._21._2014_AngularWebAPI.adapters.Data;
using _11._21._2014_AngularWebAPI.Models;
using _11._21._2014_AngularWebAPI.Extensions;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;

namespace _11._21._2014_AngularWebAPI.Controllers
{
    public class MessageController : ApiController
    {
        private IMessageAdapter _adapter;

        public MessageController()
        {
            _adapter = new MessageDataAdapter();
        }

        public IHttpActionResult Get()
        {
            List<MessageViewModel> models = _adapter.GetMessageViewModels();

            //Format the object like Firebase does it just to make it a little bit easier to change our JavaScript API calls
            var result = models.ToFirebaseResult(m => m.Id);

            return Ok(result);
        }

        public IHttpActionResult Post(MessageViewModel model)
        {
            int id = _adapter.CreateMessage(model);
            return Ok(new { name = id });
        }
    }
}
